// game.js
import PageManager from './src/managers/PageManager.js';
import ScreenAdapter from './src/utils/ScreenAdapter.js'; // 导入适配器

let canvas, ctx;
let screenAdapter;
let pageManager;

function startGame() {
  canvas = wx.createCanvas();
  ctx = canvas.getContext('2d');

  // 初始化屏幕适配器
  screenAdapter = new ScreenAdapter();
  canvas.width = screenAdapter.canvasWidth;
  canvas.height = screenAdapter.canvasHeight;

  // 初始化页面管理器并启动
  pageManager = new PageManager(canvas, ctx, screenAdapter);
  pageManager.start(); // 启动游戏（包含资源加载）

  // 启动游戏循环
  requestAnimationFrame(gameLoop);
}

let lastTime = 0;
function gameLoop(currentTime) {
  const dt = currentTime - lastTime;
  lastTime = currentTime;

  pageManager.update(dt);
  pageManager.render();

  requestAnimationFrame(gameLoop);
}

startGame();
